#!/bin/sh
set -e # fail on errors

# Redirect stderr -> stdout
exec 2>&1

<%= render("mount_point_check.erb") %>

cd <%= node['gitlab']['gitlab-workhorse']['dir'] %>

exec chpst -e /opt/gitlab/etc/gitlab-workhorse/env -P \
  -U <%= node['gitlab']['user']['username'] %> \
  -u <%= node['gitlab']['user']['username'] %> \
  /opt/gitlab/embedded/bin/gitlab-workhorse \
    -listenNetwork <%= node['gitlab']['gitlab-workhorse']['listen_network'] %> \
    -listenUmask <%= node['gitlab']['gitlab-workhorse']['listen_umask'] %> \
    -listenAddr <%= node['gitlab']['gitlab-workhorse']['listen_addr'] %> \
    -authBackend <%= node['gitlab']['gitlab-workhorse']['auth_backend'] %><%= node['gitlab']['gitlab-workhorse']['relative_url'] %> \
    -authSocket <%= node['gitlab']['gitlab-workhorse']['auth_socket'] %> \
    -documentRoot /opt/gitlab/embedded/service/gitlab-rails/public \
    -pprofListenAddr <%= node['gitlab']['gitlab-workhorse']['pprof_listen_addr'] %>\
    <% if node['gitlab']['gitlab-workhorse']['proxy_headers_timeout'] %>
    -proxyHeadersTimeout <%= node['gitlab']['gitlab-workhorse']['proxy_headers_timeout'] %>
    <% end %>
